package com.zkingsoft.services.web.impl;

import com.zkingsoft.dao.web.WebAdcolumnDao;
import org.springframework.beans.factory.annotation.Autowired;
import com.zkingsoft.util.ModelUtils;
import com.zkingsoft.pojo.PaginationVO;
import java.util.List;
import com.zkingsoft.services.web.WebAdcolumnService;
import com.zkingsoft.sqlUtil.ServiceUtil;

import org.springframework.stereotype.Service;
import com.zkingsoft.exception.GlobleException;
import java.util.Map;
import com.zkingsoft.model.web.WebAdcolumn;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-12-20 15:50
 */
@Service("webAdcolumnService")
public class WebAdcolumnServiceImpl implements WebAdcolumnService {

	@Autowired
	private WebAdcolumnDao webAdcolumnDao;
	@Autowired
	private ServiceUtil serviceUtil;

	private String tableName = "web_adcolumn";

	@Override
	public int add(WebAdcolumn webAdcolumn) {
		if (serviceUtil.addCheckRepeat(tableName, "code", webAdcolumn.getCode())) {
			throw new GlobleException("code值已经存在");
		}

		return webAdcolumnDao.insert(webAdcolumn);

	}

	@Override
	public int batchAdd(List<WebAdcolumn> webAdcolumnList) {
		return webAdcolumnDao.batchInsert(webAdcolumnList);
	}

	@Override
	public int modifyByMap(WebAdcolumn oldWebAdcolumn, WebAdcolumn newWebAdcolumn) {
		if (serviceUtil.updateCheckRepeat(tableName, "code", newWebAdcolumn.getCode(), "col_id",
				oldWebAdcolumn.getColId())) {
			throw new GlobleException("code值已经存在");
		}

		if (!ModelUtils.isModified(oldWebAdcolumn, newWebAdcolumn)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldWebAdcolumn, newWebAdcolumn);
		} catch (Exception e) {
			new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("colId", oldWebAdcolumn.getColId());
			webAdcolumnDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(WebAdcolumn webAdcolumn) {

		return webAdcolumnDao.updateByModel(webAdcolumn);

	}

	@Override
	public int remove(List<Long> list) {

		return webAdcolumnDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long colId) {

		return webAdcolumnDao.deleteById(colId);

	}

	@Override
	public int removeByModel(WebAdcolumn webAdcolumn) {

		return webAdcolumnDao.deleteByModel(webAdcolumn);

	}

	@Override
	public List<WebAdcolumn> findInPage(WebAdcolumn webAdcolumn, PaginationVO pageVo) {

		return webAdcolumnDao.selectInPage(webAdcolumn, pageVo);

	}

	@Override
	public List<WebAdcolumn> findByModel(WebAdcolumn webAdcolumn) {

		return webAdcolumnDao.selectByModel(webAdcolumn);

	}

	@Override
	public int findTotal(WebAdcolumn webAdcolumn) {

		return webAdcolumnDao.selectTotalRecord(webAdcolumn);

	}

	@Override
	public WebAdcolumn findById(Long colId) {

		return webAdcolumnDao.selectById(colId);

	}
	
	@Override
	public List<WebAdcolumn> findByRemark() {
		return webAdcolumnDao.selectRemark();
	}

}